package com.ncell.cell;

import com.ncell.utils.Utils;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

public class PIUnit {

    private final List<P> ps = new ArrayList<>();
    private final List<I> is = new ArrayList<>();
    private final List<I> TPlist = new LinkedList<>();
    private final int width;
    private final int height;

    public List<I> getTPlist() {
        return TPlist;
    }

    public PIUnit(int pWidth, int pHeight, int iCount) {
        createPField(pWidth, pHeight);
        createIArray(pWidth, pHeight, iCount);
        this.width = pWidth;
        this.height = pHeight;
    }

    private void createIArray(int pWidth, int pHeight, int iCount) {
        for (int i = 0; i < iCount; i++) {
            I seeker = new I(true);
            seeker.setX(Utils.getRandomFloat(pWidth));
            seeker.setY(Utils.getRandomFloat(pHeight));
            seeker.setOarkn(0);
            is.add(seeker);
        }
    }

    private void createPField(int width, int height) {
        int count = width * height;
        for (int i = 0; i < count; i++) {
            P p = new P();
            int y = i / width;
            int x = i - y * width;
            p.setX(x);
            p.setY(y);
            ps.add(p);
        }
    }

    public List<P> getPs() {
        return ps;
    }

    public List<I> getIs() {
        return is;
    }

    public int getWidth() {
        return width;
    }

    public int getHeight() {
        return height;
    }
}
